--[[
战斗的loading场景
]]
local BaseScene = require("engin.mvcs.view.BaseScene")
local FightLoadingScene = class("FightLoadingScene", BaseScene)



function FightLoadingScene:ctor(param)
	FightLoadingScene.super.ctor(self,param)
	
    
	self.stepIndex   = 0

    self.steps = {}
    
    
    self.steps[#self.steps + 1] = function()
       --加载数据
       --string.format("Lv%04d_map", i);
       local level = param.level;--地图
       local levelModuleName    = string.format("app.data.level.Lv%04d_map", level);
	   local ok, data = pcall(function() return require(levelModuleName) end)
	   if not ok or type(data) ~= "table" then
	   		echoj("当前没有数据！！！",levelModuleName);
	   		ok, data = pcall(function() return require("app.data.level.Lv0001_map") end)
	   end
	   
	   data.levelId = level;
	   self.param_ = {levelData = data};
	   
    end
    
    
    self.steps[#self.steps + 1] = function()
         display.addSpriteFramesListName(GamePlistProperties.Sheet_Map());
    end
    self.steps[#self.steps + 1] = function()
         display.addSpriteFramesListName(GamePlistProperties.Sheet_Fight());
    end
     
end




function FightLoadingScene:tick()
    local count = #self.steps
    if self.stepIndex < count then
    	self.stepIndex = self.stepIndex + 1
	    local ok, err = pcall(self.steps[self.stepIndex])
	    if ok then
	        echoj("加载进度：",self.stepIndex / count * 100)
	    else
	        echoj(err)
	    end
    elseif self.stepIndex >= count then
        self:unscheduleUpdate()
        self:performWithDelay(function()
        	
        	local sceneParam;
        	if DEBUG_MAP == 2 then --DEBUG_MAP = 0 --0表示非debug模式  1表示调试地图  2表示编辑器模式
        		sceneParam = SceneConstants.EditorScene();
        	else
        		sceneParam = SceneConstants.FightScene();
        	end
        	
        	sceneParam.param = self.param_;
        	app:enterScene(sceneParam)
        	
        	
        end, 0.1)
    end
end



function FightLoadingScene:onTouch(event, x, y)
end


function FightLoadingScene:onCleanup()
end


return FightLoadingScene
